In [12]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline
plt.rc("figure", figsize=(12,9))

Création d'une grille

In [23]:
x, y = np.linspace(-2, 2, 200), np.linspace(-2, 2, 200)
X, Y = np.meshgrid(x, y)

Création des valeurs

In [28]:
Z = (X**2-Y**2)/(1+X**2+Y**2)

Affichage

In [35]:
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_surface(X, Y, Z)
Out[35]:
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x7f2cd2658048>

Utilisation d'un code couleur

In [36]:
fig = plt.figure()
ax = Axes3D(fig)
surf = ax.plot_surface(X, Y, Z, cmap=plt.cm.viridis)
fig.colorbar(surf)
Out[36]:
<matplotlib.colorbar.Colorbar at 0x7f2cc3ebae10>

Pour faire tourner la figure

In [43]:
ax.view_init(20, 60)
fig
Out[43]: